package cn.tedu.file;
/**
 * @Author 金帮嘉诚  @Date 2021-06-17 周四 13:47
 */
/*本类用于测试字符流的读取*/

import java.io.*;

/**
 * 知识点：
 * Reader()
 * FileReader()
 * BufferedReader()
 */
public class TestIn2 {
    public static void main(String[] args) {
        method1();//普通字符输入
        System.out.println("*******");
        method2();//高效字符输入
    }

    private static void method1() {
        Reader in = null;

        try {
//            in =
//                    new FileReader
//                            (new File("D:\\ready\\1.txt"));
            in =
                    new FileReader(
                            "D:\\ready\\1.txt");

            int b;
            while ((b = in.read()) != -1) {
                System.out.println(b);
            }
//            in.close();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {//代码块
            try {
                in.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    private static void method2() {
        Reader in = null;

        try {
//            in=
//                    new BufferedReader
//                            (new FileReader
//                                    (new File
//                                            ("D:\\ready\\1.txt")));
            in =
                    new BufferedReader(
                            new FileReader("D:\\ready\\1.txt"));
            int b;
            while ((b = in.read()) != -1) {
                System.out.println(b);
            }
//            in.close();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                in.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }
}
